package liuch.basic;

/**
 * 〈一句话功能简述〉测试runable的可用性，run方法加锁<br>
 * 〈功能详细描述〉
 *
 * @author 17101651 on 2018/7/12.
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class RunableSynchronizedTest implements Runnable {
    private int a = 10;

    @Override
    public synchronized void run() {
        System.out.println("进入" + Thread.currentThread().getName() + "|" + a);
        for (int i = 0; i <= 100 && a > 0; i++) {
            a--;
            System.out.println(Thread.currentThread().getName() + "|" + a);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        RunableSynchronizedTest runableTest = new RunableSynchronizedTest();
        new Thread(runableTest).start();
        new Thread(runableTest).start();
        new Thread(runableTest).start();
    }
}
